home *** CD-ROM | disk | FTP | other *** search
- /* TC2CS - Converts TurboC map file to one readable by Lattice C-Sprite debugger
- * Jim Deming 6-10-87 Terripin Station
- * The map file that is build by Turbo C is not acceptable by C-Sprite. This
- * program takes the Turbo map file and builds one that is acceptable by
- * C-Sprite. If you have a newer C-Sprite that doesn't like what I have done,
- * then you have the opportunity to improve on the following.
- * Assumptions:
- * - version 2.01 of C-Sprite, yes I know it is an old one.
- * - version 1.0 of Turbo C
- * - PC DOS 3.2
- * - you do not need DGROUP & PGROUP that C-Sprite picks up from Lattice C
- * - I used the small memory model to build the .exe
- * - extension .TCM will not conflict with other files
- */
- #include <dir.h>
- #include <fcntl.h>
- #include <stdio.h>
-
- extern int errno;
-
- char drive[MAXDRIVE];
- char dir[MAXDIR];
- char file[MAXFILE];
- char ext[MAXEXT];
-
- /* full path names built in next two fields to test for double identity */
- char file1[MAXPATH];
- char file2[MAXPATH];
-
- const char map_cnst[] = ".MAP";
- const char tcm_cnst[] = ".TCM";
- void usage();
-
- void main(argc, argv)
- int argc;
- char *argv[];
- {
- char *fone=NULL, *ftwo=NULL;
- char name[MAXFILE];
- FILE *fp1, *fp2, *fopen();
- int i;
- int first_time=1;
- char string[128];
-
- /* no command line arguments */
- if (argc < 2) usage();
-
- /* determine what files will be used */
- while ( *++argv )
- {
- if( fone )
- {
- if( ftwo )
- {
- printf("tc2cs: too many parameters on command line\n\n");
- usage();
- }
- ftwo = *argv;
- } else {
- fone = *argv;
- build_path( file1, fone );
- }
- }
- strcpy( name, file ); /* file will be changed in build_path() */
- if( ftwo )
- {
- if( !( build_path( file2, ftwo ) & FILENAME ) )
- {
- strcat( file2, name );
- strcat( file2, map_cnst );
- }
- } else {
- strcat( file2, file );
- strcat( file2, map_cnst );
- build_path( file2, file2 );
- }
-
- /* if source and target are the same, rename extension from MAP to TCM */
- if( ! stricmp( file1, file2 ) )
- {
- printf("Changing the extension of %s to %s\n", file1, tcm_cnst );
- strncpy( &file1[ strlen( file1 )-4 ], tcm_cnst, 4 );
- unlink( file1 );
- if( rename( file2, file1 ) )
- {
- printf("tc2cs: Rename failed with DOS error %x\n", errno );
- exit(1);
- }
- }
- /*
- printf("%s\n", file1 );
- printf("%s\n", file2 );
- */
-
- /* open files */
- if ((fp1 = fopen( file1, "rt")) == NULL)
- {
- printf("tc2cs: cannot open %s\n", file1);
- exit(1);
- }
- if ((fp2 = fopen( file2, "wt")) == NULL)
- {
- printf("tc2cs: cannot open target file %s\n", file2);
- exit(1);
- }
-
- /* essense this program */
- while( fgets(string, 128, fp1) )
- {
- if( first_time )
- {
- if( string[5] == ':' )
- {
- first_time=0;
- fputs(" Address Publics by Name\n\n", fp2);
- fputs(" Address Publics by Value\n\n", fp2);
- } else continue;
- }
- if( string[0] == ' ' ) /* C-Sprite likes upper case & no '@'s */
- {
- i = 17;
- while( string[i] )
- {
- if( string[i] == '@' )
- string[i] = 'A';
- else
- string[i] = toupper( string[i] );
- i++;
- }
- }
- if( fputs( string, fp2 ) )
- {
- printf("tc2cs: Failed writing to target file.\n");
- exit(1);
- }
- } /* endwhile */
-
- /* close of program */
- printf("Successful\n");
- fclose(fp1);
- fclose(fp2);
- }
-
- build_path( p, q )
- char *p, *q;
- {
- int flag;
-
- flag = fnsplit( q, drive, dir, file, ext );
- if( !(flag & DRIVE) )
- {
- drive[0] = getdisk() + 'A';
- drive[1] = ':';
- }
- *drive = toupper( *drive );
- strcpy( p, drive );
- if( !(flag & DIRECTORY) )
- {
- dir[0] = '\\';
- getcurdir( drive[0]-'A'+1, &dir[1] );
- strcat( dir, "\\" );
- }
- strcat( p, dir );
- strcat( p, file );
- strcat( p, ext );
- return( flag );
- }
-
- void usage()
- {
- printf("Usage: tc2cs [a:][\path\]infile [b:][\path\][outfile]\n\n");
- printf(" Takes a map file created by Turbo C and creates a map file to be\n");
- printf("used by C-Sprite. If the source file will have the same name as the\n");
- printf("destination file, the source will be renamed with TCM extension.\n");
- exit(0);
- }